home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #ifndef COMM_H
- #define COMM_H
-
- #include <sys/types.h>
- #include <netinet/in.h>
- #include "sw.h"
-
- typedef struct in_addr InAddr;
- typedef fd_set FD_TYPE;
-
- struct NetId {
- public:
- NetId();
- NetId(const char* addr_in_network_byte_order);
- NetId(InAddr& a);
- NetId(InAddr* a);
- operator InAddr () const;
- int operator == (const NetId&) const;
- int operator != (const NetId&) const;
- int isAny() const;
-
- public:
- InAddr id; // network id
- };
-
- struct PlayerInfo {
- public:
- InAddr id;
- Team team;
- char name[MAXNAMELEN];
- ShipClass shipClass;
- };
-
- struct TeamInfo {
- public:
- Team team; // team this is info for
- int players; // players on this team
- int won, lost; // team score
- float position[3]; // flag position
- FlagState state; // flag status
- InAddr owner; // ship that has flag (if any)
- };
-
- // Information that all objects in space need to have
- // (No pointers or virtual functions allowed, nor objects with the same!)
- // If active is not ObjectActive, no other fields have any valid meaning
- struct ObjectInfo {
- public:
- Active active; // ObjectActive if really exists
- float mass; // object mass
- float position[3]; // xyz
- float velocity[3]; // dx dy dz
- float orientation[4]; // quaternion orientation
- float direction[3]; // thrust direction
- float explodeTime; // exploding if > 0.0
- float engineOutput; // fraction of max (0-1)
- };
-
- // All the data in ShipInfo is broadcast to other systems
- // (No pointers or virtual functions allowed, nor objects with the same!)
- struct ShipInfo {
- public:
- InAddr myId; // my host address
-
- // game info
- int won, lost; // score
- Team flag; // which flag ship has
-
- // spacecraft info
- ObjectInfo info;
-
- // laser info (position & direction only set if firingLaser is TRUE)
- int firingLaser; // boolean
- float laserDirection[3]; // direction laser points in
- float beamLength; // distance to hit
-
- // missile info
- ObjectInfo missile[MAXMISSILES]; // missile info
-
- // shield info
- float shieldStrength[6]; // fraction max strength
- float shieldHits[MAXHITS][4]; // frac max (1), position (3)
- };
-
- struct BroadcastPacket {
- public:
- InAddr serverId; // host address of server
- int length; // message length
- ShipInfo message;
- };
-
- // List of all message types to and from server
- enum ServerMessageType { SwNone, // no message
- SwJoin, // (to) join game
- SwQuit, // (to) leave game
- SwGetWorld, // (to) request world database
- SwAlive, // (to) now alive
- SwGrabFlag, // (to) request for flag
- SwDropFlag, // (to) release flag
- SwCaptureFlag, // (to) captured flag
- SwAddPlayer, // (from) new player joined
- SwRemovePlayer, // (from) player quit
- SwFlagUpdate, // (from) team and flag info
- SwFlagGrabbed, // (from) flag grabbed
- SwFlagDropped, // (from) flag released
- SwFlagCaptured, // (from) flag captured
- SwWorld, // (from) world info
- SwKilled, // (to/from) someone killed
- SwHit, // (to/from) hit something
- SwMessage // (to/from) info message
- };
-
- // Each message has it's own information structure
- struct SwJoinMessage {
- public:
- PlayerInfo p; // info on player
- };
-
- struct SwQuitMessage {
- public:
- // no data
- };
-
- struct SwGetWorldMessage {
- public:
- // no data
- };
-
- struct SwAliveMessage {
- public:
- // no data
- };
-
- struct SwGrabFlagMessage {
- public:
- Team team; // team number whose flag it is
- };
-
- struct SwDropFlagMessage {
- public:
- Team team; // team whose flag it is
- float position[3]; // where dropped
- };
-
- struct SwCaptureFlagMessage {
- public:
- Team flagTeam; // team whose flag it is
- Team captorTeam; // team who captured flag
- };
-
- struct SwAddPlayerMessage {
- public:
- PlayerInfo p; // info on player
- };
-
- struct SwRemovePlayerMessage {
- public:
- InAddr id; // id of player quiting
- };
-
- struct SwFlagUpdateMessage {
- public:
- TeamInfo info; // team information
- };
-
- struct SwFlagGrabbedMessage {
- public:
- InAddr grabber; // ship that grabbed flag
- TeamInfo info; // new team information
- };
-
- struct SwFlagDroppedMessage {
- public:
- InAddr dropper; // ship that dropped flag
- TeamInfo info; // new team information
- };
-
- struct SwFlagCapturedMessage {
- public:
- InAddr captor; // ship that captured flag
- TeamInfo flagTeam; // team whose flag it is
- TeamInfo captorTeam; // team who captured flag
- };
-
- enum WorldType { WorldNone = 0,
- WorldTeam = 1,
- WorldPlayer = 2 };
-
- struct SwWorldMessage {
- public:
- WorldType type; // type of info
- int count; // number of messages to go
- union {
- PlayerInfo player;
- TeamInfo team;
- } info;
- };
-
- struct SwKilledMessage {
- public:
- InAddr killer; // who killed
- InAddr victim; // who got killed
- };
-
- // if missileNum == -1:
- // position = local direction of ship (normalize)
- // else
- // position = position of impact in space
- // momentum is in world space (mass already accounted for)
- struct SwHitMessage {
- public:
- InAddr hitter; // who did hitting
- InAddr victim; // who has been hit
- int missileNum; // -1 if ship, else missile
- float position[3]; // position of hit
- float velocityChange[3]; // momentum imparted
- float energy; // energy of hit
- };
-
- struct SwMessageMessage {
- public:
- InAddr source; // who sent it
- InAddr target; // who's it about
- Team team; // or which team
- char msg[81]; // null terminated string
- };
-
- // AnyMessage can hold exactly one of any type of message
- union SwAnyMessage {
- // public:
- SwJoinMessage join;
- SwQuitMessage quit;
- SwGetWorldMessage getWorld;
- SwAliveMessage alive;
- SwGrabFlagMessage grabFlag;
- SwDropFlagMessage dropFlag;
- SwCaptureFlagMessage captureFlag;
- SwAddPlayerMessage addPlayer;
- SwRemovePlayerMessage removePlayer;
- SwFlagUpdateMessage flagUpdate;
- SwFlagGrabbedMessage flagGrabbed;
- SwFlagDroppedMessage flagDropped;
- SwFlagCapturedMessage flagCaptured;
- SwWorldMessage world;
- SwKilledMessage killed;
- SwHitMessage hit;
- SwMessageMessage message;
- };
-
- // ServerPacket holds one message plus type and size info for that message
- struct ServerPacket {
- public:
- int length; // length of message
- ServerMessageType type; // message type
- SwAnyMessage any; // message
- };
-
- // openBroadcastSocket() returns socket fd (-1 on failure)
- int openBroadcastSocket(int port, struct sockaddr_in*);
-
- #endif
-